#!/usr/bin/env python

#    "data": {
#        "atlas_server": "https://atlas.ripe.net", 
#        "authenticated": true, 
#        "measurements": [
#            {
#                "af": 4, 
#                "all_scheduling_requests_fulfilled": true, 
#                "can_visualise": false, 
#                "creation_time": 1385392776, 
#                "description": "google drive", 
#                "dst_addr": "64.15.126.103", 
#                "dst_asn": 43515, 
#                "dst_name": "64.15.126.103", 
#                "firsthop": 1, 
#                "interval": 1800, 
#                "is_oneoff": false, 
#                "is_public": true, 
#                "maxhops": 32, 
#                "msm_id": 1041601, 
#                "paris": 16, 
#                "participant_count": 33, 
#                "protocol": "ICMP", 
#                "resolve_on_probe": false, 
#                "resolved_ips": [
#                    "64.15.126.103"
#                ], 
#                "response_timeout": 4000, 
#                "result": "/api/v1/measurement/1041601/result/", 
#                "size": 40, 
#                "start_time": 1385463600, 
#                "status": {
#                    "id": 4, 
#                    "name": "Stopped"
#                }, 
#                "stop_time": 1385470800, 
#                "type": {
#                    "id": 2, 
#                    "name": "traceroute"
#                }

import urllib2, urllib, json

#Base Restful API requirements
key = "20cf1905-41c9-4e3d-b83f-93c06769caa7"
url = "https://atlas.ripe.net/api/v1/measurement/?key=%s" % key
request = urllib2.Request(url)
request.add_header("Content-Type", "application/json")
request.add_header("Accept", "application/json")


#Measurement specification parameters
#--------------------------------------------------------------------------------------------------
#Base measurement definitions section
target = ""
measurementType = ""
addressFamily = ""

#Probe characteristics of measurement section
requested = ""
probeSelectionType = ""
#--------------------------------------------------------------------------------------------------

data = { "definitions": 
         [
           { 
             "target": "194.71.107.27", 
             "description": "EU ping thepiratebay",
             "type": "ping", 
             "af": "4",
             "is_oneoff": False
           } 
         ],
         "probes":[{'requested': '1', 'type': 'country', 'value': 'CA'}],
         #"start_time": "1392509400",
         #"stop_time": "1392510000"
       }


#for country in ["AD", "AL", "AT", "BA", "BE", "BG", "BY", "CH", "CY", "CZ", "DE", "DK", "EE", "ES", "FI", "FO", "FR", "GG", "GI", "GR", "HR", "HU", "IE", "IM", "IS", "IT", "JE", "LI", "LT", "LU", #"LV", "MC", "MD", "MK", "MT", "NL", "NO", "PL", "PT", "RO", "RU", "SE", "SI", "SJ", "SK", "SM", "TR", "UA", "UK", "VA", "YU"]:
    
#    data["probes"][0].update([{"requested": "1", "type": "country", "value": str(country)}])

print data


conn = urllib2.urlopen(request, json.dumps(data))
